package com.yyk.yykywd.mvvm.adapter

import android.content.Context
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.yyk.yykywd.*
import com.yyk.yykywd.mvvm.entity.AgentListBean
import com.yyk.yykywd.mvvm.entity.SearchBean

/**
 * 文件描述：
 * Created by guo on 2019-11-19.
 */
class SearchAdapter(private val context: Context,
                    layoutResId: Int,
                    data: List<SearchBean.Data>) : BaseQuickAdapter<SearchBean.Data, BaseViewHolder>(layoutResId, data) {
    private lateinit var type: String

    fun setType(type: String) {
        this.type = type
    }

    override fun convert(helper: BaseViewHolder, item: SearchBean.Data) {
        helper.setText(R.id.tv_agent, item.client_name)
        helper.setText(R.id.tv_agent_contact, item.phone)
        helper.setText(R.id.tv_region, item.area)
        helper.setText(R.id.tv_hospital, item.client_name)
        helper.setText(R.id.tv_hospital_type, item.type_name)
        helper.setText(R.id.tv_visitor, item.ccname)
        helper.setText(R.id.tv_contact, item.phone)
        val tvStatus: TextView = helper.getView(R.id.tv_status)

        if (item.belong_type == 1) {
            helper.setText(R.id.tv_founder, "创建人：" + item.addname)
            helper.setText(R.id.tv_create_time, "创建时间：" + getCommonTime(item.create_time))
        } else {
            helper.setText(R.id.tv_founder, "认领人：" + item.meetname)
            helper.setText(R.id.tv_create_time, "认领时间：" + getCommonTime(item.update_time))
        }
        val clAgent: ConstraintLayout = helper.getView(R.id.cl_agent)
        val clHospital: ConstraintLayout = helper.getView(R.id.cl_hospital)
        val clContract: ConstraintLayout = helper.getView(R.id.cl_contract)
        clContract.visibility = View.GONE
        val tvAgentContactHint: TextView = helper.getView(R.id.tv_agent_contact_hint)
        val tvAgentContact: TextView = helper.getView(R.id.tv_agent_contact)
        val tvVisitorHint: TextView = helper.getView(R.id.tv_visitor_hint)
        val tvVisitor: TextView = helper.getView(R.id.tv_visitor)
        val tvContactHint: TextView = helper.getView(R.id.tv_contact_hint)
        val tvContact: TextView = helper.getView(R.id.tv_contact)
        val tv_type: TextView = helper.getView(R.id.tv_type)
        tvStatus.setBackgroundResource(R.drawable.shape_2dp4)
        tvStatus.setTextColor(ContextCompat.getColor(context, R.color.col_5987ff))
        if (item.common_type == 1) {
            tvStatus.text = "公海客户"
            tvAgentContactHint.visibility = View.GONE
            tvAgentContact.visibility = View.GONE
            tvVisitorHint.visibility = View.GONE
            tvVisitor.visibility = View.GONE
            tvContactHint.visibility = View.GONE
            tvContact.visibility = View.GONE
            if (type == AGENT) {
                clAgent.visibility = View.VISIBLE
                clHospital.visibility = View.GONE
                tv_type.setBackgroundResource(R.color.col_f5c161)
            } else {
                clAgent.visibility = View.GONE
                clHospital.visibility = View.VISIBLE
                tv_type.setBackgroundResource(R.color.col_68c3d4)
            }
        } else {
            tvStatus.text = item.flag_name

            if (type == AGENT) {
                clAgent.visibility = View.VISIBLE
                clHospital.visibility = View.GONE
                tvAgentContactHint.visibility = View.VISIBLE
                tvAgentContact.visibility = View.VISIBLE
                tvVisitorHint.visibility = View.GONE
                tvVisitor.visibility = View.GONE
                tvContactHint.visibility = View.GONE
                tvContact.visibility = View.GONE
                tv_type.setBackgroundResource(R.color.col_f5c161)
            } else {
                clAgent.visibility = View.GONE
                clHospital.visibility = View.VISIBLE
                tvAgentContactHint.visibility = View.GONE
                tvAgentContact.visibility = View.GONE
                tvVisitorHint.visibility = View.VISIBLE
                tvVisitor.visibility = View.VISIBLE
                tvContactHint.visibility = View.VISIBLE
                tvContact.visibility = View.VISIBLE
                tv_type.setBackgroundResource(R.color.col_68c3d4)
            }
        }

    }
}